Skip to content

test: add litesvm ts testcases#585

Open
aarjn wants to merge 1 commit into
solana-foundation:mainfrom
aarjn:cpi-test
Open

test: add litesvm ts testcases#585
aarjn wants to merge 1 commit into
solana-foundation:mainfrom
aarjn:cpi-test

Conversation

@aarjn

@aarjn aarjn commented Jun 1, 2026

Copy link
Copy Markdown

hy @Perelyn-sama raised PR here addressing the closed PR #392

Also I have noticed almost every ts test file for native program in basic are in bankrun.

@dev-jodee dev-jodee self-requested a review June 24, 2026 15:26

@dev-jodee dev-jodee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the CI gh action failure

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR moves the native CPI TypeScript test to LiteSVM. The main changes are:

  • Add litesvm to the package and lockfile.
  • Build the hand and lever SBF programs into test fixtures before running tests.
  • Replace local-validator transaction tests with LiteSVM program loading and transaction sends.

Confidence Score: 4/5

The changed test path can report success without running the new LiteSVM cases.

  • pnpm test still invokes ts-mocha.
  • The changed test imports describe, it, and before from node:test, which registers tests with a different runner.
  • LiteSVM transaction failures can also lose useful failure details in the current error path.

basics/cross-program-invocation/native/tests/test.ts

Important Files Changed

Filename Overview
basics/cross-program-invocation/native/package.json Adds LiteSVM and updates build-and-test to build both native programs into fixtures before running the existing Mocha command.
basics/cross-program-invocation/native/pnpm-lock.yaml Adds the LiteSVM dependency graph and platform-specific optional packages.
basics/cross-program-invocation/native/tests/test.ts Rewrites the CPI test to use LiteSVM, but the runner import and failure-reporting paths need fixes.

Reviews (1): Last reviewed commit: "test: add litesvm ts testcases" | Re-trigger Greptile

} from "@solana/web3.js";
import * as fs from "node:fs";
import * as path from "node:path";
import { before, describe, it } from "node:test";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mocha Sees No Tests

The package script still runs this file through ts-mocha, but these imports register suites with Node's node:test runner instead of Mocha. When pnpm test loads the file, Mocha can see an empty suite and report success without running the CPI transactions.

Suggested change
import { before, describe, it } from "node:test";
import { before, describe, it } from "mocha";

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


const res = svm.sendTransaction(tx);
if (!(res instanceof TransactionMetadata)) {
throw new Error(`Transaction failed: ${res.meta().toString()}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failure Details Are Masked

If sendTransaction returns its failed-transaction variant, this branch assumes that object has meta() and can throw a TypeError while building the error message. A real program error or funding failure would then lose the LiteSVM failure details and report the wrong exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants